class Solution {
    public void sortColors(int[] nums) {
        //三指针算法
        int left = -1;
        int right = nums.length;
        int cur = 0;
        while(cur < right){
            if(nums[cur] == 0) swap(nums, ++left, cur++);
            else if(nums[cur] == 1) cur++;
            else swap(nums, --right, cur);
        }
    }
    private void swap(int[] nums, int i, int j){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
}
